<?php

/**
 * O2O团购PC版本
 * ============================================================================
 * * 版权所有 2009-2016 郑州司科计算机科技有限公司，并保留所有权利。
 * 购买网址: http://www.jzphp.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
  * 咨询电话：400-823-0371 QQ：313999875
 * ============================================================================
 * $Author: zzsike $
 * $Time 2016-02-03 sammy $
*/


require_once(dirname(dirname(__FILE__)) . '/appwap.php');
//if(checkmobile()) die(require_once( dirname(__FILE__) . '/wap.php'));
if(!$INI['db']['host']) redirect( WEB_ROOT . '/install.php' );
if($city&&option_yes('rewritecity')){
	redirect(WEB_ROOT."/{$city['ename']}");
}
$current_hover = 'class="current"';

$request_uri = 'index';

$group_id = abs(intval($_GET['gid']));
$sub_id  =  abs(intval($_GET['sid'])); 
$area    =  abs(intval($_GET['aid']));
$shop    =  abs(intval($_GET['shop_id']));

$tag = abs(intval($_GET['tag']));
$p = $_GET['p'];
if(!$p){
 $p = 'mo';
 //$or = 'ORDER BY `sort_order` DESC, `id` DESC';
}

if($p == 'new'){$or ='ORDER BY  `id` DESC';}
if($p == 'mun') {$or ='ORDER BY  `now_number` DESC';}
if($p == 'price') {$or ='ORDER BY  `team_price` ASC';}
if($p == 'price2') {$or ='ORDER BY  `team_price` DESC';}
if($p == 'mo') {$or ='ORDER BY `sort_order` DESC, `id` DESC';} 

if (option_yes('indexmulti')&& option_yes('indexpage')) {
	$city_id = abs(intval($city['id']));
	$now = time();
	$size = abs(intval($INI['system']['indexteam']));
	if ($size<=1) return current_team($city_id);
	$condition = array( 
			'team_type' => 'goods',
			'city_id'=>$city['id'],
			"begin_time < '{$now}'",
			"end_time > '{$now}'",
			
			);
	if($group_id) $condition['group_id']=$group_id;
	if($sub_id) $condition['sub_id']=$sub_id;
	if($area) $condition['area']  = $area;
	if($shop) $condition['shop']  = $shop;
	if($tag) $condition['hottag']  = $tag;
	
	$condition[] = "(city_ids like '%@{$city_id}@%' or city_ids like '%@0@%') or (city_ids = '' and city_id in(0,{$city_id}))";
	$count = Table::Count('team', $condition);
	list($pagesize, $offset, $pagestring) = pagestring($count, $size);
	$teams = DB::LimitQuery('team', array(
				'condition' => $condition,
				'order' => $or,
				'size' => $pagesize,
				'offset' => $offset,
				));
	$disable_multi = true;
include template('wap_goods');

	$a = array('/wap/indexs.php' => '全部',

			);			
	foreach(option_hotcategory('group') AS $id=>$name) {
	$condition['group_id'] = $id;
	  $num= Table::Count('team', $condition);
		$a["/wap/indexs.php?gid=$id".$str] = $name.'('.$num.')';
	}

	$l = "/wap/index.php?gid=$gid".$str;
	if (!$gid) $l = "/wap/indexs.php";
	return current_link($l, $a, true);
}